package uy.edu.fing.pgsegesb.test;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import uy.edu.fing.pgsegesb.authentication.SAMLHelper;
import uy.edu.fing.pgsegesb.utils.RespuestaHttp;


public class MainSAML {


	public static void main(String[] args) {
		try {
			String serviceProviderURL = "http://localhost:8180/sales/";
			String idpAddress = "http://localhost:8180/idp/j_security_check";
			RespuestaHttp response;
			
	        response = SAMLHelper.loginSAML(serviceProviderURL, idpAddress, "tomcat", "tomcat");
	        System.out.println(response.SAMLtoken);
	        
	        
	    	DefaultHttpClient client = new DefaultHttpClient();
			client.getParams().setParameter("http.protocol.handle-redirects",false);
	        String nuevaURL = serviceProviderURL + "?SAMLResponse=" + response.SAMLtoken;
			HttpResponse r = client.execute(new HttpGet(nuevaURL));
			System.out.println(nuevaURL);
	        System.out.println(r.getStatusLine().getStatusCode());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
